]> dgit.raspbian.org Git - gnome-shell.git/commitdiff
support arrow-up to recall previous commands
authorMaxim Ermilov <zaspire@rambler.ru>
Wed, 17 Mar 2010 15:22:27 +0000 (18:22 +0300)
committerMaxim Ermilov <zaspire@rambler.ru>
Thu, 18 Mar 2010 19:05:09 +0000 (22:05 +0300)
runDialog store history in gconf.
https://bugzilla.gnome.org/show_bug.cgi?id=612635

data/gnome-shell.schemas
js/ui/runDialog.js

index bc3dd425ab69311b9c6c9516afc74aaa5e319c17..6153b34e940cc9b47383d7e7fb6571077b56ef80 100644 (file)
        </locale>
       </schema>
 
+      <schema>
+        <key>/schemas/desktop/gnome/shell/run_dialog/history</key>
+       <applyto>/desktop/gnome/shell/run_dialog/history</applyto>
+       <owner>gnome-shell</owner>
+       <type>list</type>
+       <list_type>string</list_type>
+       <default>[]</default>
+       <locale name="C">
+         <short>History for command (Alt-F2) dialog</short>
+       </locale>
+      </schema>
+
       <schema>
         <key>/schemas/desktop/gnome/shell/sidebar/visible</key>
        <applyto>/desktop/gnome/shell/sidebar/visible</applyto>
index 7808780be75a2029ac318e2bea099ff87943c4db..2cd85186838b9a98fa6a70958ab67360f6a7138a 100644 (file)
@@ -18,6 +18,9 @@ const Main = imports.ui.main;
 
 const MAX_FILE_DELETED_BEFORE_INVALID = 10;
 
+const HISTORY_KEY = 'run_dialog/history';
+const HISTORY_LIMIT = 512;
+
 function CommandCompleter() {
     this._init();
 }
@@ -174,11 +177,19 @@ RunDialog.prototype = {
     _init : function() {
         this._isOpen = false;
 
-        let gconf = Shell.GConf.get_default();
-        gconf.connect('changed::development_tools', Lang.bind(this, function () {
-            this._enableInternalCommands = gconf.get_boolean('development_tools');
+        this._gconf = Shell.GConf.get_default();
+        this._gconf.connect('changed::development_tools', Lang.bind(this, function () {
+            this._enableInternalCommands = this._gconf.get_boolean('development_tools');
+        }));
+        this._enableInternalCommands = this._gconf.get_boolean('development_tools');
+
+        this._history = this._gconf.get_string_list(HISTORY_KEY);
+        this._historyIndex = -1;
+
+        this._gconf.connect('changed::' + HISTORY_KEY, Lang.bind(this, function() {
+            this._history = this._gconf.get_string_list(HISTORY_KEY);
+            this._historyIndex = this._history.length;
         }));
-        this._enableInternalCommands = gconf.get_boolean('development_tools');
 
         this._internalCommands = { 'lg':
                                    Lang.bind(this, function() {
@@ -249,6 +260,14 @@ RunDialog.prototype = {
         this._group.connect('notify::visible', Lang.bind(this._commandCompleter, this._commandCompleter.update));
         this._entryText.connect('key-press-event', Lang.bind(this, function(o, e) {
             let symbol = e.get_key_symbol();
+            if (symbol == Clutter.Down) {
+                this._setCommandFromHistory(this._historyIndex++);
+                return true;
+            }
+            if (symbol == Clutter.Up) {
+                this._setCommandFromHistory(this._historyIndex--);
+                return true;
+            }
             if (symbol == Clutter.Return) {
                 if (e.get_state() & Clutter.ModifierType.CONTROL_MASK)
                     this._run(o.get_text(), true);
@@ -301,8 +320,19 @@ RunDialog.prototype = {
         }
     },
 
+    _saveHistory : function() {
+        if (this._history.length > HISTORY_LIMIT) {
+            this._history.splice(0, this._history.length - HISTORY_LIMIT);
+        }
+        this._gconf.set_string_list(HISTORY_KEY, this._history);
+    },
+
     _run : function(input, inTerminal) {
         let command = input;
+
+        this._history.push(input);
+        this._saveHistory();
+
         this._commandError = false;
         let f;
         if (this._enableInternalCommands)
@@ -350,6 +380,22 @@ RunDialog.prototype = {
         }
     },
 
+    _setCommandFromHistory: function(lastI) {
+        if (this._historyIndex < 0)
+            this._historyIndex = 0;
+        if (this._historyIndex > this._history.length)
+            this._historyIndex = this._history.length;
+
+        let text = this._entryText.get_text();
+        if (text) {
+            this._history[lastI] = text;
+        }
+        if (this._history[this._historyIndex]) {
+            this._entryText.set_text(this._history[this._historyIndex]);
+        } else
+            this._entryText.set_text('');
+    },
+
     open : function() {
         if (this._isOpen) // Already shown
             return;
@@ -360,6 +406,8 @@ RunDialog.prototype = {
         // Position the dialog on the current monitor
         let monitor = global.get_focus_monitor();
 
+        this._historyIndex = this._history.length;
+
         this._box.set_position(monitor.x, monitor.y);
         this._box.set_size(monitor.width, monitor.height);